package com.atguigu.yygh.hosp.controller.api;

import com.atguigu.yygh.common.exception.YyghException;
import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.DeparmentService;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.HospitalSetQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp/hospital")
@Api(tags="查询设置管理")
public class HospApiController {


      @Autowired
    private HospitalService  hospitalService;



    @Autowired
    private DeparmentService  deparmentService;

    @ApiOperation(value = "查询医院列表")
     @GetMapping("findHospList/{page}/{limit}")
public Result  findHospList(@PathVariable  Long page,
                            @PathVariable  Long limit,
                            HospitalQueryVo hospitalSetQueryVo){

      if(page>0&&limit>0)    {

          Page<Hospital> hospitalPage   =hospitalService.selectHospPage(page,limit,hospitalSetQueryVo);


          return  Result.ok(hospitalPage);
      }else{

          throw new YyghException("页码值不正确",201);
      }




      }

  @ApiOperation(value = "更具医院名称查询")
    @GetMapping("findByHosName/{hosname}")
    public  Result  findByHosName(@PathVariable String hosname){

      List<Hospital> list   =hospitalService.findByHosname(hosname);

      return  Result.ok(list);
  }




    @ApiOperation(value = "更具医院编号获取科室信息")
    @GetMapping("department/{hoscode}")
    public  Result department(@PathVariable String hoscode){


        List<DepartmentVo> deptTree = deparmentService.findDeptTree(hoscode);

        return Result.ok(deptTree);
    }




    @ApiOperation(value = "更具医院编号获取预约挂号详情信息")
    @GetMapping("findHospDetail/{hoscode}")
    public  Result  findHospDetail(@PathVariable String hoscode){

                Map<String,Object> map  =  hospitalService.item(hoscode);


                return Result.ok(map);
    }
















}
